{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 6.1 Letter Casing and Whitespace"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Risk</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>MARRIOT MARQUIS CHICAGO</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>JETS PIZZA</td>\n",
       "      <td>Risk 2 (Medium)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>ROOM 1520</td>\n",
       "      <td>Risk 3 (Low)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>MARRIOT MARQUIS CHICAGO</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>CHARTWELLS</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>153805</th>\n",
       "      <td>WOLCOTT'S</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>153806</th>\n",
       "      <td>DUNKIN DONUTS/BASKIN-ROBBINS</td>\n",
       "      <td>Risk 2 (Medium)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>153807</th>\n",
       "      <td>Cafe 608</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>153808</th>\n",
       "      <td>mr.daniel's</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>153809</th>\n",
       "      <td>TEMPO CAFE</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>153810 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                      Name             Risk\n",
       "0               MARRIOT MARQUIS CHICAGO       Risk 1 (High)\n",
       "1                              JETS PIZZA   Risk 2 (Medium)\n",
       "2                               ROOM 1520      Risk 3 (Low)\n",
       "3                MARRIOT MARQUIS CHICAGO      Risk 1 (High)\n",
       "4                            CHARTWELLS       Risk 1 (High)\n",
       "...                                    ...              ...\n",
       "153805                         WOLCOTT'S      Risk 1 (High)\n",
       "153806     DUNKIN DONUTS/BASKIN-ROBBINS     Risk 2 (Medium)\n",
       "153807                           Cafe 608     Risk 1 (High)\n",
       "153808                        mr.daniel's     Risk 1 (High)\n",
       "153809                         TEMPO CAFE     Risk 1 (High)\n",
       "\n",
       "[153810 rows x 2 columns]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "inspections = pd.read_csv(\"chicago_food_inspections.csv\")\n",
    "inspections"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0     MARRIOT MARQUIS CHICAGO   \n",
       "1                    JETS PIZZA \n",
       "2                     ROOM 1520 \n",
       "3      MARRIOT MARQUIS CHICAGO  \n",
       "4                  CHARTWELLS   \n",
       "Name: Name, dtype: object"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "inspections[\"Name\"].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([' MARRIOT MARQUIS CHICAGO   ', ' JETS PIZZA ', '   ROOM 1520 ',\n",
       "       '  MARRIOT MARQUIS CHICAGO  ', ' CHARTWELLS   '], dtype=object)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "inspections[\"Name\"].head().values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<pandas.core.strings.accessor.StringMethods at 0x7ff009724490>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "inspections[\"Name\"].str"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'cheesecake  '"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dessert = \"  cheesecake  \"\n",
    "dessert.lstrip()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'  cheesecake'"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dessert.rstrip()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'cheesecake'"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dessert.strip()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    MARRIOT MARQUIS CHICAGO   \n",
       "1                   JETS PIZZA \n",
       "2                    ROOM 1520 \n",
       "3     MARRIOT MARQUIS CHICAGO  \n",
       "4                 CHARTWELLS   \n",
       "Name: Name, dtype: object"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "inspections[\"Name\"].str.lstrip().head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0      MARRIOT MARQUIS CHICAGO\n",
       "1                   JETS PIZZA\n",
       "2                    ROOM 1520\n",
       "3      MARRIOT MARQUIS CHICAGO\n",
       "4                   CHARTWELLS\n",
       "Name: Name, dtype: object"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "inspections[\"Name\"].str.rstrip().head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    MARRIOT MARQUIS CHICAGO\n",
       "1                 JETS PIZZA\n",
       "2                  ROOM 1520\n",
       "3    MARRIOT MARQUIS CHICAGO\n",
       "4                 CHARTWELLS\n",
       "Name: Name, dtype: object"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "inspections[\"Name\"].str.strip().head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "inspections[\"Name\"] = inspections[\"Name\"].str.strip()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['Name', 'Risk'], dtype='object')"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "inspections.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "for column in inspections.columns:\n",
    "    inspections[column] = inspections[column].str.strip()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    marriot marquis chicago\n",
       "1                 jets pizza\n",
       "2                  room 1520\n",
       "3    marriot marquis chicago\n",
       "4                 chartwells\n",
       "Name: Name, dtype: object"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "inspections[\"Name\"].str.lower().head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0     porterhouse\n",
       "1    filet mignon\n",
       "2          ribeye\n",
       "dtype: object"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "steaks = pd.Series([\"porterhouse\", \"filet mignon\", \"ribeye\"])\n",
    "steaks"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0     PORTERHOUSE\n",
       "1    FILET MIGNON\n",
       "2          RIBEYE\n",
       "dtype: object"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "steaks.str.upper()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    Marriot marquis chicago\n",
       "1                 Jets pizza\n",
       "2                  Room 1520\n",
       "3    Marriot marquis chicago\n",
       "4                 Chartwells\n",
       "Name: Name, dtype: object"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "inspections[\"Name\"].str.capitalize().head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    Marriot Marquis Chicago\n",
       "1                 Jets Pizza\n",
       "2                  Room 1520\n",
       "3    Marriot Marquis Chicago\n",
       "4                 Chartwells\n",
       "Name: Name, dtype: object"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "inspections[\"Name\"].str.title().head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 6.2 String Slicing"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0      Risk 1 (High)\n",
       "1    Risk 2 (Medium)\n",
       "2       Risk 3 (Low)\n",
       "3      Risk 1 (High)\n",
       "4      Risk 1 (High)\n",
       "Name: Risk, dtype: object"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "inspections[\"Risk\"].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "153810"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(inspections)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['Risk 1 (High)', 'Risk 2 (Medium)', 'Risk 3 (Low)', 'All', nan],\n",
       "      dtype=object)"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "inspections[\"Risk\"].unique()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "inspections = inspections.dropna(subset = [\"Risk\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['Risk 1 (High)', 'Risk 2 (Medium)', 'Risk 3 (Low)', 'All'],\n",
       "      dtype=object)"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "inspections[\"Risk\"].unique()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "inspections = inspections.replace(\n",
    "    to_replace = \"All\", value = \"Risk 4 (Extreme)\"\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['Risk 1 (High)', 'Risk 2 (Medium)', 'Risk 3 (Low)',\n",
       "       'Risk 4 (Extreme)'], dtype=object)"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "inspections[\"Risk\"].unique()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 6.2.1 String Slicing and Character Replacement"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    1\n",
       "1    2\n",
       "2    3\n",
       "3    1\n",
       "4    1\n",
       "Name: Risk, dtype: object"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "inspections[\"Risk\"].str.slice(5, 6).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    1\n",
       "1    2\n",
       "2    3\n",
       "3    1\n",
       "4    1\n",
       "Name: Risk, dtype: object"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "inspections[\"Risk\"].str[5:6].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0      High)\n",
       "1    Medium)\n",
       "2       Low)\n",
       "3      High)\n",
       "4      High)\n",
       "Name: Risk, dtype: object"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "inspections[\"Risk\"].str.slice(8).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0      High)\n",
       "1    Medium)\n",
       "2       Low)\n",
       "3      High)\n",
       "4      High)\n",
       "Name: Risk, dtype: object"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "inspections[\"Risk\"].str[8:].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0      High\n",
       "1    Medium\n",
       "2       Low\n",
       "3      High\n",
       "4      High\n",
       "Name: Risk, dtype: object"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "inspections[\"Risk\"].str.slice(8, -1).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0      High\n",
       "1    Medium\n",
       "2       Low\n",
       "3      High\n",
       "4      High\n",
       "Name: Risk, dtype: object"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "inspections[\"Risk\"].str[8:-1].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "<ipython-input-33-b0d7687b1461>:1: FutureWarning: The default value of regex will change from True to False in a future version. In addition, single character regular expressions will*not* be treated as literal strings when regex=True.\n",
      "  inspections[\"Risk\"].str.slice(8).str.replace(\")\", \"\").head()\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "0      High\n",
       "1    Medium\n",
       "2       Low\n",
       "3      High\n",
       "4      High\n",
       "Name: Risk, dtype: object"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "inspections[\"Risk\"].str.slice(8).str.replace(\")\", \"\").head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 6.3 Boolean Methods"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"Pizza\" in \"Jets Pizza\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"pizza\" in \"Jets Pizza\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    False\n",
       "1     True\n",
       "2    False\n",
       "3    False\n",
       "4    False\n",
       "Name: Name, dtype: bool"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "inspections[\"Name\"].str.lower().str.contains(\"pizza\").head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Risk</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>JETS PIZZA</td>\n",
       "      <td>Risk 2 (Medium)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>NANCY'S HOME OF STUFFED PIZZA</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>NARY'S GRILL &amp; PIZZA ,INC.</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>NARYS GRILL &amp; PIZZA</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>68</th>\n",
       "      <td>COLUTAS PIZZA</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>153756</th>\n",
       "      <td>ANGELO'S STUFFED PIZZA CORP</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>153764</th>\n",
       "      <td>COCHIAROS PIZZA #2</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>153772</th>\n",
       "      <td>FERNANDO'S MEXICAN GRILL &amp; PIZZA</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>153788</th>\n",
       "      <td>REGGIO'S PIZZA EXPRESS</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>153801</th>\n",
       "      <td>State Street Pizza Company</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3992 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                    Name             Risk\n",
       "1                             JETS PIZZA  Risk 2 (Medium)\n",
       "19         NANCY'S HOME OF STUFFED PIZZA    Risk 1 (High)\n",
       "27            NARY'S GRILL & PIZZA ,INC.    Risk 1 (High)\n",
       "29                   NARYS GRILL & PIZZA    Risk 1 (High)\n",
       "68                         COLUTAS PIZZA    Risk 1 (High)\n",
       "...                                  ...              ...\n",
       "153756       ANGELO'S STUFFED PIZZA CORP    Risk 1 (High)\n",
       "153764                COCHIAROS PIZZA #2    Risk 1 (High)\n",
       "153772  FERNANDO'S MEXICAN GRILL & PIZZA    Risk 1 (High)\n",
       "153788            REGGIO'S PIZZA EXPRESS    Risk 1 (High)\n",
       "153801        State Street Pizza Company    Risk 1 (High)\n",
       "\n",
       "[3992 rows x 2 columns]"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "has_pizza = inspections[\"Name\"].str.lower().str.contains(\"pizza\")\n",
    "inspections[has_pizza]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    False\n",
       "1    False\n",
       "2    False\n",
       "3    False\n",
       "4    False\n",
       "Name: Name, dtype: bool"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "inspections[\"Name\"].str.lower().str.startswith(\"tacos\").head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Risk</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>69</th>\n",
       "      <td>TACOS NIETOS</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>556</th>\n",
       "      <td>TACOS EL TIO 2 INC.</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>675</th>\n",
       "      <td>TACOS DON GABINO</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>958</th>\n",
       "      <td>TACOS EL TIO 2 INC.</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1036</th>\n",
       "      <td>TACOS EL TIO 2 INC.</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>143587</th>\n",
       "      <td>TACOS DE LUNA</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>144026</th>\n",
       "      <td>TACOS GARCIA</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>146174</th>\n",
       "      <td>Tacos Place's 1</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>147810</th>\n",
       "      <td>TACOS MARIO'S LIMITED</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>151191</th>\n",
       "      <td>TACOS REYNA</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>105 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                         Name           Risk\n",
       "69               TACOS NIETOS  Risk 1 (High)\n",
       "556       TACOS EL TIO 2 INC.  Risk 1 (High)\n",
       "675          TACOS DON GABINO  Risk 1 (High)\n",
       "958       TACOS EL TIO 2 INC.  Risk 1 (High)\n",
       "1036      TACOS EL TIO 2 INC.  Risk 1 (High)\n",
       "...                       ...            ...\n",
       "143587          TACOS DE LUNA  Risk 1 (High)\n",
       "144026           TACOS GARCIA  Risk 1 (High)\n",
       "146174        Tacos Place's 1  Risk 1 (High)\n",
       "147810  TACOS MARIO'S LIMITED  Risk 1 (High)\n",
       "151191            TACOS REYNA  Risk 1 (High)\n",
       "\n",
       "[105 rows x 2 columns]"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "starts_with_tacos = (\n",
    "    inspections[\"Name\"].str.lower().str.startswith(\"tacos\")\n",
    ")\n",
    "inspections[starts_with_tacos]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Risk</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>382</th>\n",
       "      <td>LAZO'S TACOS</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>569</th>\n",
       "      <td>LAZO'S TACOS</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2652</th>\n",
       "      <td>FLYING TACOS</td>\n",
       "      <td>Risk 3 (Low)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3250</th>\n",
       "      <td>JONY'S TACOS</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3812</th>\n",
       "      <td>PACO'S TACOS</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>151121</th>\n",
       "      <td>REYES TACOS</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>151318</th>\n",
       "      <td>EL MACHO TACOS</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>151801</th>\n",
       "      <td>EL MACHO TACOS</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>153087</th>\n",
       "      <td>RAYMOND'S TACOS</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>153504</th>\n",
       "      <td>MIS TACOS</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>304 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                   Name           Risk\n",
       "382        LAZO'S TACOS  Risk 1 (High)\n",
       "569        LAZO'S TACOS  Risk 1 (High)\n",
       "2652       FLYING TACOS   Risk 3 (Low)\n",
       "3250       JONY'S TACOS  Risk 1 (High)\n",
       "3812       PACO'S TACOS  Risk 1 (High)\n",
       "...                 ...            ...\n",
       "151121      REYES TACOS  Risk 1 (High)\n",
       "151318   EL MACHO TACOS  Risk 1 (High)\n",
       "151801   EL MACHO TACOS  Risk 1 (High)\n",
       "153087  RAYMOND'S TACOS  Risk 1 (High)\n",
       "153504        MIS TACOS  Risk 1 (High)\n",
       "\n",
       "[304 rows x 2 columns]"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ends_with_tacos = (\n",
    "    inspections[\"Name\"].str.lower().str.endswith(\"tacos\")\n",
    ")\n",
    "inspections[ends_with_tacos]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 6.4 Splitting Strings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Address</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Frank Manning</td>\n",
       "      <td>6461 Quinn Groves, East Matthew, New Hampshire...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Elizabeth Johnson</td>\n",
       "      <td>1360 Tracey Ports Apt. 419, Kyleport, Vermont,...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Donald Stephens</td>\n",
       "      <td>19120 Fleming Manors, Prestonstad, Montana, 23495</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Michael Vincent III</td>\n",
       "      <td>441 Olivia Creek, Jimmymouth, Georgia, 82991</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Jasmine Zamora</td>\n",
       "      <td>4246 Chelsey Ford Apt. 310, Karamouth, Utah, 7...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                  Name                                            Address\n",
       "0        Frank Manning  6461 Quinn Groves, East Matthew, New Hampshire...\n",
       "1    Elizabeth Johnson  1360 Tracey Ports Apt. 419, Kyleport, Vermont,...\n",
       "2      Donald Stephens  19120 Fleming Manors, Prestonstad, Montana, 23495\n",
       "3  Michael Vincent III       441 Olivia Creek, Jimmymouth, Georgia, 82991\n",
       "4       Jasmine Zamora  4246 Chelsey Ford Apt. 310, Karamouth, Utah, 7..."
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "customers = pd.read_csv(\"customers.csv\")\n",
    "customers.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    13\n",
       "1    17\n",
       "2    15\n",
       "3    19\n",
       "4    14\n",
       "Name: Name, dtype: int64"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "customers[\"Name\"].str.len().head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['555', '123', '4567']"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "phone_number = \"555-123-4567\"\n",
    "phone_number.split(\"-\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0           [Frank, Manning]\n",
       "1       [Elizabeth, Johnson]\n",
       "2         [Donald, Stephens]\n",
       "3    [Michael, Vincent, III]\n",
       "4          [Jasmine, Zamora]\n",
       "Name: Name, dtype: object"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# The two lines below are equivalent\n",
    "customers[\"Name\"].str.split(pat = \" \").head()\n",
    "customers[\"Name\"].str.split(\" \").head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    2\n",
       "1    2\n",
       "2    2\n",
       "3    3\n",
       "4    2\n",
       "Name: Name, dtype: int64"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "customers[\"Name\"].str.split(\" \").str.len().head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0          [Frank, Manning]\n",
       "1      [Elizabeth, Johnson]\n",
       "2        [Donald, Stephens]\n",
       "3    [Michael, Vincent III]\n",
       "4         [Jasmine, Zamora]\n",
       "Name: Name, dtype: object"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "customers[\"Name\"].str.split(pat = \" \", n = 1).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0        Frank\n",
       "1    Elizabeth\n",
       "2       Donald\n",
       "3      Michael\n",
       "4      Jasmine\n",
       "Name: Name, dtype: object"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "customers[\"Name\"].str.split(pat = \" \", n = 1).str.get(0).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0        Manning\n",
       "1        Johnson\n",
       "2       Stephens\n",
       "3    Vincent III\n",
       "4         Zamora\n",
       "Name: Name, dtype: object"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "customers[\"Name\"].str.split(pat = \" \", n = 1).str.get(1).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0        Manning\n",
       "1        Johnson\n",
       "2       Stephens\n",
       "3    Vincent III\n",
       "4         Zamora\n",
       "Name: Name, dtype: object"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "customers[\"Name\"].str.split(pat = \" \", n = 1).str.get(-1).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Frank</td>\n",
       "      <td>Manning</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Elizabeth</td>\n",
       "      <td>Johnson</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Donald</td>\n",
       "      <td>Stephens</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Michael</td>\n",
       "      <td>Vincent III</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Jasmine</td>\n",
       "      <td>Zamora</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           0            1\n",
       "0      Frank      Manning\n",
       "1  Elizabeth      Johnson\n",
       "2     Donald     Stephens\n",
       "3    Michael  Vincent III\n",
       "4    Jasmine       Zamora"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "customers[\"Name\"].str.split(\n",
    "    pat = \" \", n = 1, expand = True\n",
    ").head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Frank</td>\n",
       "      <td>Manning</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Elizabeth</td>\n",
       "      <td>Johnson</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Donald</td>\n",
       "      <td>Stephens</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Michael</td>\n",
       "      <td>Vincent</td>\n",
       "      <td>III</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Jasmine</td>\n",
       "      <td>Zamora</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           0         1     2\n",
       "0      Frank   Manning  None\n",
       "1  Elizabeth   Johnson  None\n",
       "2     Donald  Stephens  None\n",
       "3    Michael   Vincent   III\n",
       "4    Jasmine    Zamora  None"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "customers[\"Name\"].str.split(pat = \" \", expand = True).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [],
   "source": [
    "customers[[\"First Name\", \"Last Name\"]] = customers[\n",
    "    \"Name\"\n",
    "].str.split(pat = \" \", n = 1, expand = True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Address</th>\n",
       "      <th>First Name</th>\n",
       "      <th>Last Name</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Frank Manning</td>\n",
       "      <td>6461 Quinn Groves, East Matthew, New Hampshire...</td>\n",
       "      <td>Frank</td>\n",
       "      <td>Manning</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Elizabeth Johnson</td>\n",
       "      <td>1360 Tracey Ports Apt. 419, Kyleport, Vermont,...</td>\n",
       "      <td>Elizabeth</td>\n",
       "      <td>Johnson</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Donald Stephens</td>\n",
       "      <td>19120 Fleming Manors, Prestonstad, Montana, 23495</td>\n",
       "      <td>Donald</td>\n",
       "      <td>Stephens</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Michael Vincent III</td>\n",
       "      <td>441 Olivia Creek, Jimmymouth, Georgia, 82991</td>\n",
       "      <td>Michael</td>\n",
       "      <td>Vincent III</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Jasmine Zamora</td>\n",
       "      <td>4246 Chelsey Ford Apt. 310, Karamouth, Utah, 7...</td>\n",
       "      <td>Jasmine</td>\n",
       "      <td>Zamora</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9956</th>\n",
       "      <td>Dana Browning</td>\n",
       "      <td>762 Andrew Views Apt. 254, North Paul, New Mex...</td>\n",
       "      <td>Dana</td>\n",
       "      <td>Browning</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9957</th>\n",
       "      <td>Amanda Anderson</td>\n",
       "      <td>44188 Day Crest Apt. 901, Lake Marcia, Maine, ...</td>\n",
       "      <td>Amanda</td>\n",
       "      <td>Anderson</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9958</th>\n",
       "      <td>Eric Davis</td>\n",
       "      <td>73015 Michelle Squares, Watsonville, West Virg...</td>\n",
       "      <td>Eric</td>\n",
       "      <td>Davis</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9959</th>\n",
       "      <td>Taylor Hernandez</td>\n",
       "      <td>129 Keith Greens, Haleyfurt, Oklahoma, 98916</td>\n",
       "      <td>Taylor</td>\n",
       "      <td>Hernandez</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9960</th>\n",
       "      <td>Sherry Nicholson</td>\n",
       "      <td>355 Griffin Valley, Davidtown, New Mexico, 17581</td>\n",
       "      <td>Sherry</td>\n",
       "      <td>Nicholson</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>9961 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                     Name                                            Address  \\\n",
       "0           Frank Manning  6461 Quinn Groves, East Matthew, New Hampshire...   \n",
       "1       Elizabeth Johnson  1360 Tracey Ports Apt. 419, Kyleport, Vermont,...   \n",
       "2         Donald Stephens  19120 Fleming Manors, Prestonstad, Montana, 23495   \n",
       "3     Michael Vincent III       441 Olivia Creek, Jimmymouth, Georgia, 82991   \n",
       "4          Jasmine Zamora  4246 Chelsey Ford Apt. 310, Karamouth, Utah, 7...   \n",
       "...                   ...                                                ...   \n",
       "9956        Dana Browning  762 Andrew Views Apt. 254, North Paul, New Mex...   \n",
       "9957      Amanda Anderson  44188 Day Crest Apt. 901, Lake Marcia, Maine, ...   \n",
       "9958           Eric Davis  73015 Michelle Squares, Watsonville, West Virg...   \n",
       "9959     Taylor Hernandez       129 Keith Greens, Haleyfurt, Oklahoma, 98916   \n",
       "9960     Sherry Nicholson   355 Griffin Valley, Davidtown, New Mexico, 17581   \n",
       "\n",
       "     First Name    Last Name  \n",
       "0         Frank      Manning  \n",
       "1     Elizabeth      Johnson  \n",
       "2        Donald     Stephens  \n",
       "3       Michael  Vincent III  \n",
       "4       Jasmine       Zamora  \n",
       "...         ...          ...  \n",
       "9956       Dana     Browning  \n",
       "9957     Amanda     Anderson  \n",
       "9958       Eric        Davis  \n",
       "9959     Taylor    Hernandez  \n",
       "9960     Sherry    Nicholson  \n",
       "\n",
       "[9961 rows x 4 columns]"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "customers"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [],
   "source": [
    "customers = customers.drop(labels = \"Name\", axis = \"columns\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Address</th>\n",
       "      <th>First Name</th>\n",
       "      <th>Last Name</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>6461 Quinn Groves, East Matthew, New Hampshire...</td>\n",
       "      <td>Frank</td>\n",
       "      <td>Manning</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1360 Tracey Ports Apt. 419, Kyleport, Vermont,...</td>\n",
       "      <td>Elizabeth</td>\n",
       "      <td>Johnson</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>19120 Fleming Manors, Prestonstad, Montana, 23495</td>\n",
       "      <td>Donald</td>\n",
       "      <td>Stephens</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>441 Olivia Creek, Jimmymouth, Georgia, 82991</td>\n",
       "      <td>Michael</td>\n",
       "      <td>Vincent III</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4246 Chelsey Ford Apt. 310, Karamouth, Utah, 7...</td>\n",
       "      <td>Jasmine</td>\n",
       "      <td>Zamora</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                             Address First Name    Last Name\n",
       "0  6461 Quinn Groves, East Matthew, New Hampshire...      Frank      Manning\n",
       "1  1360 Tracey Ports Apt. 419, Kyleport, Vermont,...  Elizabeth      Johnson\n",
       "2  19120 Fleming Manors, Prestonstad, Montana, 23495     Donald     Stephens\n",
       "3       441 Olivia Creek, Jimmymouth, Georgia, 82991    Michael  Vincent III\n",
       "4  4246 Chelsey Ford Apt. 310, Karamouth, Utah, 7...    Jasmine       Zamora"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "customers.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 6.5 Coding Challenge"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 6.5.1 Problems"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 6.5.2 Solutions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    [6461 Quinn Groves,  East Matthew,  New Hampsh...\n",
       "1    [1360 Tracey Ports Apt. 419,  Kyleport,  Vermo...\n",
       "2    [19120 Fleming Manors,  Prestonstad,  Montana,...\n",
       "3    [441 Olivia Creek,  Jimmymouth,  Georgia,  82991]\n",
       "4    [4246 Chelsey Ford Apt. 310,  Karamouth,  Utah...\n",
       "Name: Address, dtype: object"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "customers[\"Address\"].str.split(\",\").head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    [6461 Quinn Groves, East Matthew, New Hampshir...\n",
       "1    [1360 Tracey Ports Apt. 419, Kyleport, Vermont...\n",
       "2    [19120 Fleming Manors, Prestonstad, Montana, 2...\n",
       "3       [441 Olivia Creek, Jimmymouth, Georgia, 82991]\n",
       "4    [4246 Chelsey Ford Apt. 310, Karamouth, Utah, ...\n",
       "Name: Address, dtype: object"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "customers[\"Address\"].str.split(\", \").head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>6461 Quinn Groves</td>\n",
       "      <td>East Matthew</td>\n",
       "      <td>New Hampshire</td>\n",
       "      <td>16656</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1360 Tracey Ports Apt. 419</td>\n",
       "      <td>Kyleport</td>\n",
       "      <td>Vermont</td>\n",
       "      <td>31924</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>19120 Fleming Manors</td>\n",
       "      <td>Prestonstad</td>\n",
       "      <td>Montana</td>\n",
       "      <td>23495</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>441 Olivia Creek</td>\n",
       "      <td>Jimmymouth</td>\n",
       "      <td>Georgia</td>\n",
       "      <td>82991</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4246 Chelsey Ford Apt. 310</td>\n",
       "      <td>Karamouth</td>\n",
       "      <td>Utah</td>\n",
       "      <td>76252</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                            0             1              2      3\n",
       "0           6461 Quinn Groves  East Matthew  New Hampshire  16656\n",
       "1  1360 Tracey Ports Apt. 419      Kyleport        Vermont  31924\n",
       "2        19120 Fleming Manors   Prestonstad        Montana  23495\n",
       "3            441 Olivia Creek    Jimmymouth        Georgia  82991\n",
       "4  4246 Chelsey Ford Apt. 310     Karamouth           Utah  76252"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "customers[\"Address\"].str.split(\", \", expand = True).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [],
   "source": [
    "new_cols = [\"Street\", \"City\", \"State\", \"Zip\"]\n",
    "\n",
    "customers[new_cols] = customers[\"Address\"].str.split(\n",
    "    pat = \", \", expand = True\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>First Name</th>\n",
       "      <th>Last Name</th>\n",
       "      <th>Street</th>\n",
       "      <th>City</th>\n",
       "      <th>State</th>\n",
       "      <th>Zip</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Frank</td>\n",
       "      <td>Manning</td>\n",
       "      <td>6461 Quinn Groves</td>\n",
       "      <td>East Matthew</td>\n",
       "      <td>New Hampshire</td>\n",
       "      <td>16656</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Elizabeth</td>\n",
       "      <td>Johnson</td>\n",
       "      <td>1360 Tracey Ports Apt. 419</td>\n",
       "      <td>Kyleport</td>\n",
       "      <td>Vermont</td>\n",
       "      <td>31924</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Donald</td>\n",
       "      <td>Stephens</td>\n",
       "      <td>19120 Fleming Manors</td>\n",
       "      <td>Prestonstad</td>\n",
       "      <td>Montana</td>\n",
       "      <td>23495</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Michael</td>\n",
       "      <td>Vincent III</td>\n",
       "      <td>441 Olivia Creek</td>\n",
       "      <td>Jimmymouth</td>\n",
       "      <td>Georgia</td>\n",
       "      <td>82991</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Jasmine</td>\n",
       "      <td>Zamora</td>\n",
       "      <td>4246 Chelsey Ford Apt. 310</td>\n",
       "      <td>Karamouth</td>\n",
       "      <td>Utah</td>\n",
       "      <td>76252</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  First Name    Last Name                      Street          City  \\\n",
       "0      Frank      Manning           6461 Quinn Groves  East Matthew   \n",
       "1  Elizabeth      Johnson  1360 Tracey Ports Apt. 419      Kyleport   \n",
       "2     Donald     Stephens        19120 Fleming Manors   Prestonstad   \n",
       "3    Michael  Vincent III            441 Olivia Creek    Jimmymouth   \n",
       "4    Jasmine       Zamora  4246 Chelsey Ford Apt. 310     Karamouth   \n",
       "\n",
       "           State    Zip  \n",
       "0  New Hampshire  16656  \n",
       "1        Vermont  31924  \n",
       "2        Montana  23495  \n",
       "3        Georgia  82991  \n",
       "4           Utah  76252  "
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "customers.drop(labels = \"Address\", axis = \"columns\").head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [],
   "source": [
    "del customers[\"Address\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>First Name</th>\n",
       "      <th>Last Name</th>\n",
       "      <th>Street</th>\n",
       "      <th>City</th>\n",
       "      <th>State</th>\n",
       "      <th>Zip</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>9956</th>\n",
       "      <td>Dana</td>\n",
       "      <td>Browning</td>\n",
       "      <td>762 Andrew Views Apt. 254</td>\n",
       "      <td>North Paul</td>\n",
       "      <td>New Mexico</td>\n",
       "      <td>28889</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9957</th>\n",
       "      <td>Amanda</td>\n",
       "      <td>Anderson</td>\n",
       "      <td>44188 Day Crest Apt. 901</td>\n",
       "      <td>Lake Marcia</td>\n",
       "      <td>Maine</td>\n",
       "      <td>37378</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9958</th>\n",
       "      <td>Eric</td>\n",
       "      <td>Davis</td>\n",
       "      <td>73015 Michelle Squares</td>\n",
       "      <td>Watsonville</td>\n",
       "      <td>West Virginia</td>\n",
       "      <td>03933</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9959</th>\n",
       "      <td>Taylor</td>\n",
       "      <td>Hernandez</td>\n",
       "      <td>129 Keith Greens</td>\n",
       "      <td>Haleyfurt</td>\n",
       "      <td>Oklahoma</td>\n",
       "      <td>98916</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9960</th>\n",
       "      <td>Sherry</td>\n",
       "      <td>Nicholson</td>\n",
       "      <td>355 Griffin Valley</td>\n",
       "      <td>Davidtown</td>\n",
       "      <td>New Mexico</td>\n",
       "      <td>17581</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     First Name  Last Name                     Street         City  \\\n",
       "9956       Dana   Browning  762 Andrew Views Apt. 254   North Paul   \n",
       "9957     Amanda   Anderson   44188 Day Crest Apt. 901  Lake Marcia   \n",
       "9958       Eric      Davis     73015 Michelle Squares  Watsonville   \n",
       "9959     Taylor  Hernandez           129 Keith Greens    Haleyfurt   \n",
       "9960     Sherry  Nicholson         355 Griffin Valley    Davidtown   \n",
       "\n",
       "              State    Zip  \n",
       "9956     New Mexico  28889  \n",
       "9957          Maine  37378  \n",
       "9958  West Virginia  03933  \n",
       "9959       Oklahoma  98916  \n",
       "9960     New Mexico  17581  "
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "customers.tail()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 6.6 A Note on Regular Expressions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0             6461 Quinn Groves\n",
       "1    1360 Tracey Ports Apt. 419\n",
       "2          19120 Fleming Manors\n",
       "3              441 Olivia Creek\n",
       "4    4246 Chelsey Ford Apt. 310\n",
       "Name: Street, dtype: object"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "customers[\"Street\"].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0             * Quinn Groves\n",
       "1    * Tracey Ports Apt. 419\n",
       "2           * Fleming Manors\n",
       "3           441 Olivia Creek\n",
       "4    * Chelsey Ford Apt. 310\n",
       "Name: Street, dtype: object"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "customers[\"Street\"].str.replace(\n",
    "    \"\\d{4,}\", \"*\", regex = True\n",
    ").head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 6.7 Summary"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
